package com.ruoyi.web.controller.employee;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.employee.domain.SsScheme;
import com.ruoyi.employee.service.ISsSchemeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社保方案Controller
 *
 * @author hango
 * @date 2025-10-13
 */
@RestController
@RequestMapping("/staffinfo/ssScheme")
public class SsSchemeController extends BaseController
{
    @Autowired
    private ISsSchemeService ssSchemeService;

    /**
     * 查询社保方案列表
     */
    @PreAuthorize("@ss.hasPermi('staffinfo:ssScheme:list')")
    @GetMapping("/list")
    public TableDataInfo list(SsScheme ssScheme)
    {
        startPage();
        List<SsScheme> list = ssSchemeService.selectSsSchemeList(ssScheme);
        return getDataTable(list);
    }

    /**
     * 导出社保方案列表
     */
    @PreAuthorize("@ss.hasPermi('staffinfo:ssScheme:export')")
    @Log(title = "社保方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SsScheme ssScheme)
    {
        List<SsScheme> list = ssSchemeService.selectSsSchemeList(ssScheme);
        ExcelUtil<SsScheme> util = new ExcelUtil<SsScheme>(SsScheme.class);
        util.exportExcel(response, list, "社保方案数据");
    }

    /**
     * 获取社保方案详细信息
     */
    @PreAuthorize("@ss.hasPermi('staffinfo:ssScheme:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ssSchemeService.selectSsSchemeById(id));
    }

    /**
     * 新增社保方案
     */
    @PreAuthorize("@ss.hasPermi('staffinfo:ssScheme:add')")
    @Log(title = "社保方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SsScheme ssScheme)
    {
        return toAjax(ssSchemeService.insertSsScheme(ssScheme));
    }

    /**
     * 修改社保方案
     */
    @PreAuthorize("@ss.hasPermi('staffinfo:ssScheme:edit')")
    @Log(title = "社保方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SsScheme ssScheme)
    {
        return toAjax(ssSchemeService.updateSsScheme(ssScheme));
    }

    /**
     * 删除社保方案
     */
    @PreAuthorize("@ss.hasPermi('staffinfo:ssScheme:remove')")
    @Log(title = "社保方案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        // ★ 关键：Controller 直接接收 Long[]，不再用 String
        return toAjax(ssSchemeService.deleteSsSchemeByIds(ids));
    }
}
